{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d48537d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def qian(f,x,h):\n",
    "    return (f(x + h) - f(x)) / h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1c658b10",
   "metadata": {},
   "outputs": [],
   "source": [
    "def hou(f,x,h):\n",
    "    return (f(x) - f(x -h)) / h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "baefe201",
   "metadata": {},
   "outputs": [],
   "source": [
    "def zhong(f,x,h):\n",
    "    return (f(x + h) - f(x - h)) / (2 * h)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "18d0d064",
   "metadata": {},
   "outputs": [],
   "source": [
    "def zhi(f,a,b):\n",
    "    return ((b - a) / 2) * (f(a) + f(b))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "372b8c1b",
   "metadata": {},
   "source": [
    "$$\n",
    "\\int_{a}{b}f(x)dx\\approx\\frac{h}{2}\\sum_{i=1}{n}\\left(f(x_{i})+f(x_{i-1})\\right).\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5a582c2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def pao(f,a,b):\n",
    "    return ((b - a) / 6 ) * (f(a)+ f(b)+ 4 * f((a + b) / 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "daa6d50d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "709283ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "R = 0.01\n",
    "L = 0.01\n",
    "C = 1e-8\n",
    "E = 5\n",
    "d = (4*L/C - R**2)**(1/2)\n",
    "c1 = d/(2*L)\n",
    "c2 = -R/(2*L)\n",
    "c3 = 2*E/d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "72ae52b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "t = np.arange(0,6,0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "604ab0bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "def di(t):\n",
    "    return 2*E*(1/d)*(c1*np.cos(c1*t)*np.exp(c2*t) + c2*np.sin(c1*t)*np.exp(c2*t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a23fb777",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 5.00000000e+02,  2.79785048e+02, -1.81903923e+02, -4.80578628e+02,\n",
       "       -3.57744862e+02,  7.54271936e+01,  4.38599466e+02,  4.16181218e+02,\n",
       "        3.15332238e+01, -3.76749788e+02, -4.52858393e+02, -1.33814689e+02,\n",
       "        2.98593879e+02,  4.66654078e+02,  2.26632353e+02, -2.08375553e+02,\n",
       "       -4.57580494e+02, -3.05798305e+02,  1.10793803e+02,  4.26750270e+02,\n",
       "        3.67905504e+02, -1.07631716e+01, -3.76290369e+02, -4.10468695e+02,\n",
       "       -8.68291737e+01,  3.09209731e+02,  4.32016790e+02,  1.77357865e+02,\n",
       "       -2.29228378e+02, -4.32133701e+02, -2.56674231e+02,  1.40577339e+02,\n",
       "        4.11447186e+02,  3.21291897e+02, -4.77799005e+01, -3.71567789e+02,\n",
       "       -3.68535021e+02, -4.45747580e+01,  3.14982266e+02,  3.96643137e+02,\n",
       "        1.32054399e+02, -2.44908000e+02, -4.04828836e+02, -2.10592427e+02,\n",
       "        1.65116540e+02,  3.93286912e+02,  2.76672823e+02, -7.97356899e+01,\n",
       "       -3.63155954e+02, -3.27483105e+02, -6.95970712e+00,  3.16435648e+02,\n",
       "        3.61028912e+02,  9.07578751e+01, -2.55865082e+02, -3.76205821e+02,\n",
       "       -1.67710968e+02,  1.84769046e+02,  3.72826202e+02,  2.34317290e+02,\n",
       "       -1.06880694e+02, -3.51601154e+02, -2.87676662e+02,  2.61497827e+01,\n",
       "        3.14079719e+02,  3.25612233e+02,  5.34538419e+01, -2.62549555e+02,\n",
       "       -3.46753886e+02, -1.28131920e+02,  1.99904991e+02,  3.50580341e+02,\n",
       "        1.94435531e+02, -1.29489792e+02, -3.37419161e+02, -2.49420774e+02,\n",
       "        5.49229198e+01,  3.08405894e+02,  2.90775541e+02,  2.00837827e+01,\n",
       "       -2.65405543e+02, -3.16912139e+02, -9.19070057e+01,  2.10901230e+02,\n",
       "        3.27022294e+02,  1.57183755e+02, -1.47856417e+02, -3.21093026e+02,\n",
       "       -2.12965531e+02,  7.95580595e+01,  2.99883765e+02,  2.56847998e+02,\n",
       "       -9.44884116e+00, -2.64866973e+02, -2.87070631e+02, -5.90431394e+01,\n",
       "        2.18136194e+02,  3.02582427e+02,  1.22668942e+02, -1.62286929e+02,\n",
       "       -3.03071526e+02, -1.78509871e+02,  1.00276873e+02,  2.88958373e+02,\n",
       "        2.24108204e+02, -3.52728468e+01, -2.61353841e+02, -2.57571861e+02,\n",
       "       -2.95078148e+01,  2.21985354e+02,  2.77648765e+02,  9.09536135e+01,\n",
       "       -1.73095521e+02, -2.83768189e+02, -1.46205528e+02,  1.17318963e+02,\n",
       "        2.76048090e+02,  1.92787164e+02, -5.75439165e+01, -2.55269083e+02,\n",
       "       -2.28712645e+02, -3.23428228e+00,  2.22817274e+02,  2.52567701e+02,\n",
       "        6.20605375e+01, -1.80599658e+02, -2.63560846e+02, -1.16161043e+02,\n",
       "        1.30936924e+02,  2.61543073e+02,  1.63071437e+02, -7.64395359e+01,\n",
       "       -2.46996034e+02, -2.00746271e+02,  1.98735106e+01,  2.20990221e+02,\n",
       "        2.27645090e+02,  3.59773113e+01, -1.85116032e+02, -2.42791646e+02,\n",
       "       -8.84457895e+01,  1.41391863e+02,  2.45804219e+02,  1.35106413e+02,\n",
       "       -9.21542986e+01, -2.36896419e+02, -1.73884905e+02,  3.99362442e+01,\n",
       "        2.16849305e+02,  2.03147685e+02,  1.26607919e+01, -1.86957027e+02,\n",
       "       -2.21767476e+02, -6.30939465e+01,  1.48949362e+02,  2.29162594e+02,\n",
       "        1.08999664e+02, -1.04895587e+02, -2.25308829e+02, -1.48302161e+02,\n",
       "        5.70948395e+01,  2.10724130e+02,  1.79304840e+02, -7.95866136e+00,\n",
       "       -1.86427650e+02, -2.00760739e+02, -4.01083990e+01,  1.53875885e+02,\n",
       "        2.11919267e+02,  8.48243181e+01, -1.14879633e+02, -2.12547662e+02,\n",
       "       -1.24135818e+02,  7.15063731e+01,  2.02926890e+02,  1.56310435e+02,\n",
       "       -2.59731573e+01, -1.83822939e+02, -1.80010431e+02, -1.94645193e+01,\n",
       "        1.56435611e+02,  1.94345511e+02,  6.26224204e+01, -1.22327958e+02,\n",
       "       -1.98902458e+02, -1.01490596e+02,  8.33403048e+01,  1.93750918e+02,\n",
       "        1.34324979e+02, -4.14934767e+01, -1.79425782e+02, -1.59723470e+02,\n",
       "       -1.11380366e+00,  1.56887684e+02,  1.76683324e+02,  4.24082377e+01,\n",
       "       -1.27464184e+02, -1.84637608e+02, -8.04409934e+01,  9.27750228e+01,\n",
       "        1.83469612e+02,  1.13477830e+02, -5.46455246e+01, -1.73505160e+02,\n",
       "       -1.40076232e+02,  1.50126604e+01,  1.55483846e+02,  1.59146218e+02,\n",
       "        2.41714827e+01, -1.30511210e+02, -1.69992387e+02, -6.10341090e+01,\n",
       "        9.99947078e+01,  1.72335729e+02,  9.38695142e+01, -6.55670411e+01,\n",
       "       -1.66314747e+02, -1.21216248e+02,  2.90009154e+01,  1.52466455e+02,\n",
       "        1.41920240e+02,  7.88042433e+00, -1.31688746e+02, -1.55181265e+02,\n",
       "       -4.32924458e+01,  1.05186513e+02,  1.60580999e+02,  7.55740807e+01,\n",
       "       -7.44045779e+01, -1.58091872e+02, -1.03264028e+02,  4.09510575e+01,\n",
       "        1.48066845e+02,  1.25165188e+02, -6.51513327e+00, -1.31211175e+02,\n",
       "       -1.40394472e+02, -2.72166496e+01,  1.08538053e+02,  1.48416030e+02,\n",
       "        5.86414838e+01, -8.13107421e+01, -1.49056780e+02, -8.63149726e+01,\n",
       "        5.09743749e+01,  1.42504015e+02,  1.09015972e+02, -1.90810241e+01,\n",
       "       -1.29285743e+02, -1.25798770e+02, -1.27881662e+01,  1.10235195e+02,\n",
       "        1.36030466e+02,  4.30999444e+01, -8.64417059e+01, -1.39412191e+02,\n",
       "       -7.04413368e+01,  5.91907061e+01,  1.35983619e+02,  9.35841033e+01,\n",
       "       -2.98960581e+01, -1.26111052e+02, -1.11538397e+02,  2.82053959e-02,\n",
       "        1.10460138e+02,  1.23593363e+02,  2.89582765e+01, -8.99549796e+01,\n",
       "       -1.29343110e+02, -5.56942243e+01,  6.57260214e+01,  1.28697231e+02,\n",
       "        7.89592654e+01, -3.90495347e+01, -1.21875833e+02, -9.77361599e+01,\n",
       "        1.12818790e+01,  1.09389766e+02,  1.11253761e+02,  1.62081512e+01,\n",
       "       -9.20074408e+01, -1.19016859e+02, -4.21055784e+01,  7.07102303e+01,\n",
       "        1.20821863e+02,  6.52109455e+01, -4.66389392e+01, -1.16757981e+02,\n",
       "       -8.44946355e+01,  2.10341817e+01,  1.07194271e+02,  9.91414108e+01,\n",
       "        4.82628286e+00, -9.27536105e+01, -1.08583317e+02, -2.96901509e+01,\n",
       "        7.42752096e+01,  1.12519712e+02,  5.23900991e+01, -5.27678258e+01,\n",
       "       -1.10923838e+02, -7.18974604e+01,  2.93561980e+01,  1.04036011e+02,\n",
       "        8.73676385e+01, -5.22348119e+00, -9.23441667e+01, -9.81753215e+01,\n",
       "       -1.84474288e+01,  7.65530499e+01,  1.03938099e+02,  4.05308243e+01,\n",
       "       -5.75438893e+01, -1.04527689e+02, -6.00106793e+01,  3.63267638e+01,\n",
       "        1.00068603e+02,  7.60263127e+01, -1.39881765e+01, -9.09246839e+01,\n",
       "       -8.79092243e+01, -8.36350123e+00,  7.76745138e+01,  9.52095922e+01,\n",
       "        2.96520251e+01, -6.10772239e+01, -9.77114611e+01, -4.88841318e+01,\n",
       "        4.20306171e+01,  9.54362251e+01,  6.51948950e+01, -2.15238552e+01,\n",
       "       -8.86345835e+01, -7.78855646e+01,  5.87148139e-01,  7.77676962e+01,\n",
       "        8.64522883e+01,  1.97590470e+01, -6.34787675e+01, -9.06046034e+01,\n",
       "       -3.85528555e+01,  4.65567053e+01,  9.02731113e+01,  5.49355514e+01,\n",
       "       -2.78938434e+01, -8.56062842e+01, -6.81898426e+01,  8.43993300e+00,\n",
       "        7.69568800e+01,  7.77702162e+01,  1.08452683e+01, -6.48589248e+01,\n",
       "       -8.33241192e+01, -2.90384885e+01,  4.99966519e+01,  8.47032246e+01,\n",
       "        4.52963029e+01, -3.31671276e+01, -8.19645356e+01, -5.88933712e+01,\n",
       "        1.52385516e+01,  7.53615733e+01,  6.92538601e+01,  2.89363489e+00,\n",
       "       -6.53263658e+01, -7.59747417e+01, -2.03506544e+01,  5.24433777e+01,\n",
       "        7.88400852e+01,  3.63121993e+01, -3.74168728e+01, -7.78259209e+01,\n",
       "       -5.00541876e+01,  2.10334752e+01,  7.30957206e+01,  6.09807715e+01,\n",
       "       -4.12187203e+00, -6.49869893e+01, -6.86492275e+01, -1.24883165e+01,\n",
       "        5.39898766e+01,  7.27867407e+01,  2.80064974e+01, -4.07190733e+01,\n",
       "       -7.32985146e+01, -4.17180049e+01,  2.58805429e+01,  7.02670725e+01,\n",
       "        5.30162558e+01, -1.02348446e+01, -6.39430454e+01, -6.14287520e+01,\n",
       "       -5.44108912e+00,  5.47281394e+01,  6.66358600e+01,  2.03918321e+01,\n",
       "       -4.31513355e+01, -6.84816789e+01, -3.39191900e+01,  2.98396669e+01,\n",
       "        6.69767045e+01,  4.54141156e+01, -1.54851395e+01, -6.22924070e+01,\n",
       "       -5.43833890e+01,  8.09503386e-01,  5.47482196e+01,  6.04699347e+01,\n",
       "        1.34713661e+01, -4.47917908e+01, -6.34659856e+01, -2.66817523e+01,\n",
       "        3.29736475e+01,  6.33186700e+01,  3.82174351e+01, -1.99176566e+01,\n",
       "       -6.01279792e+01, -4.75726602e+01,  6.28882840e+00,  5.41374366e+01,\n",
       "        5.43615731e+01,  7.23990839e+00, -4.57181344e+01, -5.83332479e+01,\n",
       "       -2.00203308e+01,  3.53471008e+01,  5.93797772e+01,  3.14593924e+01,\n",
       "       -2.35812093e+01, -5.75372393e+01, -4.10461380e+01,  1.10280137e+01,\n",
       "        5.29797062e+01,  4.83738713e+01,  1.68499218e+00, -4.60067869e+01,\n",
       "       -5.31566490e+01, -1.39411680e+01,  3.70254954e+01,  5.52394757e+01,\n",
       "        2.51640862e+01, -2.65274864e+01, -5.46018938e+01, -3.48440896e+01,\n",
       "        1.50628881e+01,  5.13549926e+01,  4.25608488e+01, -3.21209517e+00,\n",
       "       -4.57321725e+01, -4.80009543e+01, -8.44306225e+00,  3.80742970e+01,\n",
       "        5.09698417e+01,  1.93473663e+01, -2.88101089e+01, -5.13976446e+01,\n",
       "       -2.89981491e+01,  1.84329968e+01,  4.93388719e+01,  3.69679351e+01,\n",
       "       -7.47533587e+00, -4.49661083e+01, -4.29227939e+01, -3.51828891e+00,\n",
       "        3.85582175e+01,  4.66356495e+01,  1.40176565e+01, -3.04837789e+01,\n",
       "       -4.79940515e+01, -2.35320066e+01,  2.11806947e+01,  4.70022002e+01,\n",
       "        3.16324947e+01, -1.11330641e+01, -4.37772972e+01, -3.79710047e+01,\n",
       "        8.46515953e-01,  3.85405639e+01,  4.22945181e+01,  9.17676421e+00,\n",
       "       -3.16035195e+01, -4.44544827e+01, -1.84621048e+01,  2.33503178e+01,\n",
       "        4.44108751e+01,  2.65843823e+01, -1.42171100e+01, -4.22309195e+01,\n",
       "       -3.31870194e+01,  4.66951462e+00,  3.80826829e+01,  3.79971222e+01,\n",
       "        4.82066531e+00, -3.22240045e+01, -4.08361426e+01, -1.37983341e+01,\n",
       "        2.49874324e+01,  4.16256838e+01,  2.18465149e+01, -1.67620088e+01,\n",
       "       -4.03883140e+01, -2.86052938e+01,  7.97287429e+00,  3.72434960e+01,\n",
       "        3.37874568e+01,  9.40261811e-01, -3.23989735e+01, -3.71901660e+01,\n",
       "       -9.54471713e+00,  2.61381626e+01,  3.87022289e+01,  1.74354548e+01,\n",
       "       -1.88042737e+01, -3.83067422e+01, -2.42537620e+01,  1.07820244e+01,\n",
       "        3.60791186e+01,  2.97031470e+01, -2.47789536e+00, -3.21807284e+01,\n",
       "       -3.35617714e+01, -5.70007860e+00,  2.68485923e+01,  3.56909215e+01,\n",
       "        1.33619940e+01, -2.03817364e+01, -3.60392280e+01, -2.01543103e+01,\n",
       "        1.31249672e+01,  3.46425579e+01,  2.57757922e+01, -5.45092157e+00,\n",
       "       -3.16197090e+01, -2.99904634e+01, -2.25869197e+00,  2.71642417e+01,\n",
       "        3.26370358e+01,  9.63173397e+00, -2.15329520e+01, -3.36344658e+01,\n",
       "       -1.63232636e+01,  1.50316426e+01,  3.29834835e+01,  2.20313381e+01,\n",
       "       -7.99895510e+00, -3.07641406e+01, -2.65102751e+01,  7.89099799e-01,\n",
       "        2.71296133e+01,  2.95808157e+01,  6.24565396e+00, -2.22966679e+01,\n",
       "       -3.11367893e+01, -1.27718761e+01,  1.65333481e+01,  3.11480642e+01,\n",
       "        1.84904683e+01, -1.01445575e+01, -2.96597505e+01, -2.31500454e+01,\n",
       "        3.45629432e+00,  2.67878049e+01,  2.65576259e+01,  3.20066321e+00,\n",
       "       -2.27113559e+01, -2.85861942e+01, -9.50681981e+00,  1.76622144e+01,\n",
       "        2.91788647e+01,  1.51690078e+01, -1.19121590e+01, -2.83495476e+01,\n",
       "       -1.99337203e+01,  5.75867333e+00,  2.61801866e+01,  2.35981409e+01,\n",
       "        4.90132635e-01, -2.28148043e+01, -2.60184079e+01, -6.53066683e+00,\n",
       "        1.84507350e+01,  2.71147965e+01,  1.20783345e+01, -1.33275508e+01,\n",
       "       -2.68736604e+01, -1.68806751e+01,  7.71428215e+00,  2.53461363e+01,\n",
       "        2.07285646e+01, -1.89559775e+00, -2.26437671e+01, -2.34649999e+01,\n",
       "       -3.84235968e+00,  1.89313485e+01,  2.49911163e+01,  9.22578985e+00,\n",
       "       -1.44174224e+01, -2.52692272e+01, -1.40060490e+01,  9.34294664e+00])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "di(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa5dd921",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
